$(document).on('ready', function(e)
{
  var sending_comment = false;
  $('#publicar-comentario-btn').on('click', function(e)
  {
    e.preventDefault();
    if( !sending_comment ) {

      var $FrmComment = $('#formulario-coment');
      var $MsgResponse = $('#comments_msg_response');
      var $MsgSending = $('#comments_msg_sending');

      // Enviar comentario con ajax
      $.ajax('enviar-comentario.php',{
        data: $FrmComment.serialize(),
        type: 'post',
        dataType: 'json',
        beforeSend: function(jqXHR, Settings)
        {
          sending_comment = true;
          $MsgResponse.hide().removeClass('response_error');
          $MsgSending.show();
        },
        complete: function(jqXHR, status_text)
        {
          sending_comment = false;
          $MsgSending.hide();
        },
        error: function(jqXHR, status_text, error_thrown)
        {
          alert('Ocurrió un error al procesar la solicitud. ('
            + error_thrown + ')');
        },
        success: function(Response, status_text, jqXHR)
        {
          if( Response.error ){
            $MsgResponse.addClass('response_error');
            $('#nombre').focus();
          } else {
            $FrmComment.trigger('reset');
          }

          $MsgResponse.text(Response.message).show();
        }
      });
      /* END: $.ajax() */
    }
    /* END: if( !sending_comment ) */
  });
});